package easy;

public class Solution_1700 {
    public int countStudents(int[] students, int[] sandwiches) {
        int a = 0, b = 0;
        for (int student : students) {
            if (student == 0) {
                a++;
            } else {
                b++;
            }
        }
        for (int i = 0; i < sandwiches.length; i++) {
            if (sandwiches[i] == 0) {
                a--;
            } else {
                b--;
            }
            if (a < 0 || b < 0) {
                return sandwiches.length - i;
            }
        }

        return 0;
    }
    /*public int countStudents(int[] students, int[] sandwiches) {
        for (int i = 0, j = 0; i < sandwiches.length; i++) {
            boolean flag = false;
            for (int count = 0; count < students.length; count++, j++) {
                j %= students.length;
                if (students[j] != -1 && students[j] == sandwiches[i]) {
                    students[j] = -1;
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                return sandwiches.length - i;
            }
        }
        return 0;
    }*/

    public static void main(String[] args) {
        Solution_1700 model = new Solution_1700();
        System.out.println(model.countStudents(new int[]{1, 1, 0, 0}, new int[]{0, 1, 0, 1}));
        System.out.println(model.countStudents(new int[]{1, 1, 1, 0, 0, 1}, new int[]{1, 0, 0, 0, 1, 1}));
    }
}
